package com.k.kpp.web.easyexcel.downtemplate;

import com.k.kpp.web.util.EasyExcelUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Validated
@RequestMapping("/excel-template")
@RestController
public class ExcelTemplateController {
    @RequestMapping(value = "/download", method = RequestMethod.GET)
    public void download(HttpServletRequest request, HttpServletResponse res) throws IOException {
        //OutputStream outputStream = new FileOutputStream(new File("D:\\1.xlsx"));

        String downloadFileName = "xfzg.xlsx";
        res.setContentType("application/octet-stream;charset=iso8859-1");
        res.setHeader("Content-disposition", "attachment; filename=" + downloadFileName);

        EasyExcelUtils.genTemplate(res.getOutputStream(), PatrolStatisticsExcel.class, null, "SHEET1");
    }
}
